<template>
    <view class="header">
        <image class="img-title" src="../../static/icon/back-btn.png" @click="navigateBack" mode="" />
        <view class="title">{{ `${stock.stockName} ${stock.symbol}` }}</view>
    </view>
    <view class="main">
        <view class="section1 title">
            <view class="left">
                <view :class="['price-rate', stock.state == 0 ? 'red' : 'green']">
                    <view class="price">{{ stock.regularMarketPrice }}</view>
                    <view class="rate">
                        <view class="chajia">{{ `${stock.state == 0 ? '' : '-'}2.36` }}</view>
                        <view class="chajia-rate">
                            {{ `${stock.state == 0 ? '' : '-'}2.2%` }}
                        </view>
                    </view>
                </view>
                <image :src="`../../static/icon/market-${stock.state == 0 ? 'increase' : 'decrease'}.png`" class="red-green"
                    mode="" />
            </view>
            <view class="right">
                <!-- <image class="news" src="../../static/icon/news.png" /> -->
                <image v-if="isBuy" class="isSelf" @click="addOption(stockCode)" src="../../static/icon/isSelf.png" />
            </view>
        </view>
        <view class="section2 block">
            <view class="item">
                <view class="key">{{ $t('market.most-high') }}</view>
                <view class="value">{{ stock.highestHigh }}</view>
            </view>
            <view class="item">
                <view class="key">{{ $t('market.most-low') }}</view>
                <view class="value">{{ stock.lowestHigh }}</view>
            </view>
            <view class="item">
                <view class="key">{{ $t('market.today-open') }}</view>
                <view class="value">{{ stock.openToday }}</view>
            </view>
            <view class="item">
                <view class="key">{{ $t('market.yesterday-close') }}</view>
                <view class="value">{{ stock.previousClose }}</view>
            </view>
            <view class="item">
                <view class="key">{{ $t('market.number') }}</view>
                <view class="value">{{ stock.volumeTotal }}</view>
            </view>
            <view class="item">
                <view class="key">{{ $t('market.money') }}</view>
                <view class="value">{{ stock.moneyTotal }}</view>
            </view>
        </view>
        <view class="section3 kline">
            <scroll-view scroll-x="true" :scroll-into-view="timeId">
                <view :class="['time-type']">
                    <view v-for="(item, index) in timelist" :key="index" :id="'tab' + index" @click="changeTab(index)"
                        :class="
                            ['time-item', { active: index == currentIndex }]
                        ">
                        {{ $t(`market.${item.type}`) }}
                        <view class="slider" v-if="index == currentIndex">
                        </view>
                    </view>
                </view>
            </scroll-view>
            <!-- k线图部分 -->
            <view class="chartBox">
                <!-- #ifdef H5 -->
                <div id="chart" ref="chartDom" chart-id="chart" :class="['panel-box chart', { heightZero: isFenshi }]">
                </div>
                <!-- #endif -->
            </view>
        </view>
        <view class="section4 buy" v-if="isBuy">
            <view class="buy-type">
                <view v-for="(item, index) in typelist" :key="index" :id="'tab' + index" @click="changeType(index)" :class="
                    ['buy-item', { active: index == currentType }]
                ">
                    {{ $t(`market.buy.${item.type}`) }}
                    <view class="slider" v-if="index == currentType">
                    </view>
                </view>
            </view>
            <swiper :autoplay="false" :duration="250" :current="currentType" @change="changeIndex"
                :style="'height:' + 500 + 'rpx'" class="swiperBox">
                <swiper-item v-for="(item, index) in typelist" :key="index">
                    <template v-if="item.type == 'xianjia'">
                        <view class="form">
                            <view class="key">{{ $t('market.weituojia') }}</view>
                            <input v-model="form1.checkPrice" class="value">
                            <!-- <u-number-box v-model="form1.checkPrice" :step="0.1" :min="1" class="value"></u-number-box> -->
                        </view>
                        <view class="form">
                            <view class="key">{{ $t('market.jiaoyidanwei') }}</view>
                            <input type="text" v-model="form1.buyNum" class="value">
                        </view>
                        <view class="switch">
                            <view @click="param.buyType = 0"
                                :class="['increase', param.buyType == 0 ? 'active' : 'unactive',]">{{
                                    $t('market.buy.increase') }}</view>
                            <view @click="param.buyType = 1"
                                :class="['decrease', param.buyType != 0 ? 'active' : 'unactive',]">{{
                                    $t('market.buy.decrease') }}</view>
                        </view>
                    </template>
                    <template v-if="item.type == 'shijia'">
                        <view class="form">
                            <view class="key">{{ $t('market.jiaoyidanwei') }}</view>
                            <input type="text" v-model="form2.buyNum" class="value">
                        </view>
                        <view class="switch">
                            <view @click="param2.buyType = 0"
                                :class="['increase', param2.buyType == 0 ? 'active' : 'unactive',]">{{
                                    $t('market.buy.increase') }}</view>
                            <view @click="param2.buyType = 1"
                                :class="['decrease', param2.buyType != 0 ? 'active' : 'unactive',]">{{
                                    $t('market.buy.decrease') }}</view>
                        </view>
                    </template>
                    <view class="submit-btn" @click="show = true">{{ $t('market.buy') }}</view>
                    <!-- <view class="submit-btn" @click="submit()" v-if="isBuy">{{ $t('market.buy') }}</view> -->
                    <!-- <view class="submit-btn" @click="submit(true)" v-else>{{ $t('market.buy ') }}</view> -->
                </swiper-item>
            </swiper>
        </view>
        <!-- 紅利購買 -->
        <view class="section4 buy" v-else>
            <view :style="'height:' + 400 + 'rpx'" class="swiperBox">
                <view class="form">
                    <view class="key">{{ $t('market.jiaoyidanwei') }}</view>
                    <input type="text" v-model="param3.buyNum" class="value">
                </view>
                <view class="submit-btn" @click="show = true">{{ $t('market.hongli.buy') }}</view>
                <!-- <view class="submit-btn" @click="submit()" v-if="isBuy">{{ $t('market.buy') }}</view> -->
                <!-- <view class="submit-btn" @click="submit(true)" v-else>{{ $t('market.buy ') }}</view> -->
            </view>
        </view>
    </view>
    <u-popup v-model="show" mode="bottom" border-radius="24">
        <view class="popup">
            <view class="title">{{ `${stock.stockName} ${stock.symbol}` }}</view>
            <view class="box">
                <!-- 委託價格 -->
                <view class="boxItem" v-if="currentType == 0">
                    <view class="key">{{ $t('market.toast.price') }}</view>
                    <view class="value">{{ form1.checkPrice }}</view>
                </view>
                <!-- 委託數量 -->
                <view class="boxItem" v-if="currentType == 0">
                    <view class="key">{{ $t('market.toast.number') }}</view>
                    <view class="value">{{ form1.buyNum * 1000 }}</view>
                </view>
                <!-- 委託數量 -->
                <view class="boxItem" v-if="currentType == 1">
                    <view class="key">{{ $t('market.toast.number') }}</view>
                    <view class="value">{{ form2.buyNum * 1000 }}</view>
                </view>
                <!-- 本金 -->
                <!-- <view class="boxItem">
                    <view class="key">{{ $t('market.toast.weituo') }}</view>
                    <view class="value">{{ userInfo.allMoney }}</view>
                </view> -->
                <!-- 市值 -->
                <view class="boxItem" v-if="currentType == 1">
                    <view class="key">{{ $t('market.toast.marketPrice') }}</view>
                    <view class="value">{{ userInfo.marketPriceAll * form2.buyNum }}</view>
                </view>
                <!-- 手續費 -->
                <!-- <view class="boxItem">
                    <view class="key">{{ $t('market.toast.fee') }}</view>
                    <view class="value">{{ userInfo.allMoney }}</view>
                </view> -->
                <!-- 合計 -->
                <!-- <view class="boxItem">
                    <view class="key">{{ $t('market.toast.total') }}</view>
                    <view class="value">{{ userInfo.allMoney }}</view>
                </view> -->
                <!-- 合計可用資金 -->
                <view class="boxItem">
                    <view class="key">{{ $t('market.toast.enableMoney') }}</view>
                    <view class="value">{{ userInfo.enbleMoney }}</view>
                </view>
            </view>
            <view class="submit-btn" @click="submit()" v-if="isBuy">{{ $t('market.buy') }}</view>
            <view class="submit-btn" @click="submit(true)" v-else>{{ $t('market.buy ') }}</view>
        </view>
    </u-popup>
</template>
<script setup>
import { ref, reactive, watch, getCurrentInstance } from 'vue'
import { requestApi } from '@/api';
import { onLoad, onPullDownRefresh, onUnload } from '@dcloudio/uni-app';
import { dark, config } from '@/utils/klineconfig';
import { init, utils } from 'klinecharts'
import { Decimal } from 'decimal.js';
import { getToken, toast } from "@/utils/storage";
// 獲取this
const _this = getCurrentInstance().appContext.config.globalProperties

// 返回上一层
function navigateBack() {
    let canNavBack = getCurrentPages()
    if (canNavBack && canNavBack.length > 1) {
        uni.navigateBack()
    } else {
        history.back();
    }
}
// 添加自選
async function addOption(stockCode) {
    const { status } = await requestApi.addOption({ stockCode })
    status == 0 && toast(_this.$t('market.self.success'))
    status == 1 && toast(_this.$t('market.self.fail'))
}

const stockCode = ref()
let chart = null
const chartDom = ref(null)
const isFenshi = ref(false)// true 是 1顯示  false 不是 0 顯示

// 进入分时
function initeKline1(data, watch = false) {
    if (chart == null) {
        chart = init(chartDom.value)
        chart.removeIndicator(pan)
        chart.removeIndicator(pan1)
        chart.setStyles(dark)
        chart.setStyles({
            candle: {
                type: "area"
            }
        })
    }
    chart.applyNewData(data)
}
// 跳出分时 和 其他
let pan = null
let pan1 = null
function initeKline(data, watch = false) {
    if (chart == null) {
        chart = init(chartDom.value)
        chart.setStyles(dark)
        pan = chart.createIndicator("VOL", true, { height: 50 })
        pan1 = chart.createIndicator("MA", true, { id: "candle_pane" })
        chart.setStyles(config)
    }
    chart.applyNewData(data)
}
/*
    参数形式：
    // 获取股票代码
    // 获取股票的时间间隔
    // 获取股票的时间段
    [
        {
            // 分时
            stockCode: stockCode.value, // 获取股票代码
            interval: '1mo', // 获取股票的时间间隔
            range: '1d' // 获取股票的时间段
        },
        {
            // 五分
            stockCode: stockCode.value, // 获取股票代码
            interval: '5m', // 获取股票的时间间隔
            range: '5d' // 获取股票的时间段
        },
        {
            // 十分
            stockCode: stockCode.value, // 获取股票代码
            interval: '5m', // 获取股票的时间间隔
            range: '5d' // 获取股票的时间段
        },
    ]

*/
let stockItem = ref([])
let stock = ref({})
const marketPrice = ref()
const currentIndex = ref(1) // 当前的数据时间间隔
const timelist = [{
    id: '1',
    type: '1mo',
    interval: '1m', //瞬时
    range: '5d',
},
{
    id: '2',
    type: '5mo',
    interval: '5m',
    range: '5d',
},
{
    id: '3',
    type: '10mo',
    interval: '15m',
    range: '5d',
},
{
    id: '4',
    type: '30mo',
    interval: '30m',
    range: '1mo',
},
{
    id: '5',
    type: '1da',
    interval: '1d',
    range: '6mo',
},
{
    id: '6',
    type: '1we',
    interval: '5d',
    range: '5y',
},
{
    id: '7',
    type: '1mon',
    interval: '1m',
    range: 'max',
},
]
// 要传的参数
const option = reactive({
    stockCode: '', // 获取股票代码
    interval: '5m', // 获取股票的时间间隔
    range: '5d' // 获取股票的时间段
})
// 获取单个股票信息
async function getSingleStock() {
    const { status, data } = await requestApi.getSingleStock(option) // 异步获取股票数据
    if (status == 0 && data.length > 0) { // 如果获取成功且股票数据不为空
        const { result, stockName } = data[0]; // 获取股票的结果和股票名称
        const { indicators, timestamp, meta } = result[0]; // 获取股票的指标、时间戳和元数据
        const { quote } = indicators; // 获取股票的行情数据
        const { regularMarketPrice, symbol, rate } = meta; // 获取股票的市价、代码和涨跌率
        marketPrice.value = regularMarketPrice; // 将市价赋值给响应式变量
        let highestHigh = null // 定义响应式变量并初始化为 null
        let lowestHigh = null // 定义响应式变量并初始化为 null
        let openToday = null // 定义响应式变量并初始化为 null
        let volumeTotal = 0 // 定义响应式变量并初始化为 null
        let moneyTotal = 0 // 定义响应式变量并初始化为 null
        let moneySingle = 0 // 定义响应式变量并初始化为 null
        let buyPrice = 0 // 定义响应式变量并初始化为 null
        let total = 0
        const stockItemValue = []; // 定义一个股票数组
        for (let i = 0, len = quote[0].high.length; i < len; i++) { // 遍历股票的行情数据
            const high = quote[0].high[i]; // 获取 high 值
            const low = quote[0].low[i]; // 获取 low 值
            const open = quote[0].open[i]; // 获取 open 值
            if (i == 0) {
                openToday = open.toFixed(2)
            }
            const close = quote[0].close[i]; // 获取 close 值
            const volume = quote[0].volume[i]; // 获取 close 值 单个时间段的成交量
            if (volume != null && volume != 0) {
                volumeTotal += volume
            }
            if (high != null && low != null && volume != null && volume != 0) {
                buyPrice = (new Decimal(high).plus(low)).dividedBy(2) // 股票价格
                moneySingle = buyPrice.times(volume) // 单次购买价格

                moneyTotal += Number(moneySingle)

                total = moneyTotal.toFixed(0)
                // console.log(moneySingle.toFixed(0), total);
            }
            const time = timestamp[i] * 1000; // 获取时间戳并乘以 1000 转换为时间戳格式
            if (high != null) { // 如果 high 不为空
                stockItemValue.push({ // 将 high、low、open、close 和时间戳添加到股票数组中
                    high: Number(new Decimal(high).toFixed(3)), // 将 high 转换为数字类型并保留两位小数
                    low: Number(new Decimal(low).toFixed(3)), // 将 low 转换为数字类型并保留两位小数
                    open: Number(new Decimal(open).toFixed(3)), // 将 open 转换为数字类型并保留两位小数
                    close: Number(new Decimal(close).toFixed(3)), // 将 close 转换为数字类型并保留两位小数
                    volume: Number(new Decimal(volume).toFixed(3)), // 将 close 转换为数字类型并保留两位小数
                    timestamp: time // 添加时间戳
                });
                if (highestHigh === null || high > highestHigh) { // 判断当前 high 是否是最高的
                    highestHigh = Number(new Decimal(high).toFixed(3)); // 更新最高的 high 值
                }
                if (lowestHigh === null || low > lowestHigh) { // 判断当前 high 是否是最高的
                    lowestHigh = Number(new Decimal(low).toFixed(3)); // 更新最高的 high 值
                }
            }
        }
        stock.value = { // 将响应式变量的值更新为股票的值
            ...meta,
            ...indicators,
            stockName,
            symbol: symbol.match(/^[^\.]+/)[0], // 获取股票代码的前缀
            state: rate > 0 ? 0 : 1, // 判断股票的涨跌状态
            highestHigh,
            lowestHigh,
            openToday,
            volumeTotal: utils.formatBigNumber(Number(volumeTotal)),
            moneyTotal: utils.formatBigNumber(total),
        };
        // 獲取用戶信息
        getUserMoney(stock.value.regularMarketPrice)
        form1.checkPrice = stock.value.regularMarketPrice
        // console.log(form1.checkPrice);
        // console.log(stock.value); // 在控制台中输出股票的值
        stockItem.value = stockItemValue; // 将响应式变量的值更新为股票数组
        return stockItemValue
    }
}

const timeId = ref('')
// 改变时间间隔
function changeTab(index) {
    currentIndex.value = index
    option.interval = timelist[index].interval
    option.range = timelist[index].range
    if (currentIndex.value < 6) {
        timeId.value = 'tab' + index
    }
}
watch(currentIndex, async (n, o) => {
    if (n == 0 && o != 0) {
        // console.log('进入分时');
        chart = null
        const res = await getSingleStock()
        initeKline1(res); // 调用函数初始化股票 K 线图
    } else if (n != 0 && o == 0) {
        // console.log('跳出分时');
        chart = null
        const res = await getSingleStock()
        initeKline(res); // 调用函数初始化股票 K 线图
    } else if (n != 0) {
        // console.log('其他');
        const res = await getSingleStock()
        initeKline(res); // 调用函数初始化股票 K 线图
    }
})


const userInfo = reactive({
    nikeName: "",
    phone: "",
    allMoney: 0,
    enbleMoney: 0,
    buyMoney: 0,
    originalMoney: 0,
    freezeMoney: 0,
    profitMoney: 0,
    marketPriceAll: 0
})
async function getUserMoney(marketPrice) {
    const { data, status } = await requestApi.getUserMoney()
    if (status == 0) {
        const { nikeName, phone, allMoney, enbleMoney, buyMoney, originalMoney, freezeMoney, profitMoney } = data
        userInfo.nikeName = nikeName
        userInfo.phone = phone
        userInfo.allMoney = allMoney
        userInfo.enbleMoney = enbleMoney
        userInfo.buyMoney = buyMoney
        userInfo.originalMoney = originalMoney
        userInfo.freezeMoney = freezeMoney
        userInfo.profitMoney = profitMoney
        let regularMarketPrice = new Decimal(marketPrice)
        userInfo.marketPriceAll = regularMarketPrice.times(form1.buyNum * 1000)
    }


}
// 现价市价选择
const currentType = ref(0) // 0 是限价 1 是市价
const typeId = ref('')
const typelist = [{
    id: '1',
    type: 'xianjia',
},
{
    id: '2',
    type: 'shijia',
},
]

function changeIndex(e) {
    currentType.value = e.detail.current
}

function changeType(index) {
    if (currentType.value == index) return
    currentType.value = index
    if (currentType.value < 6) {
        typeId.value = 'tab' + index
    }
}

const form1 = reactive({// 限价
    checkPrice: '',
    buyNum: 1
})
const param = reactive({
    stockCode: '',
    buyType: 0, // 购买方向：0：买涨，1：买跌
    lever: 5, // 杠杆倍数
})
const form2 = reactive({// 市价
    buyNum: 1
})
const param2 = reactive({
    stockCode: '',
    buyType: 0, // 购买方向：0：买涨，1：买跌
    lever: 5, // 杠杆倍数
})

const param3 = reactive({
    id: '', // 
    buyNum: '', // 
})


// 表单验证规则
const rules0 = reactive({ // 限价
    checkPrice: [
        {
            rule: /^-?\d+(\.\d+)?$/,
            message: "請輸入正確的購買價格",
        },
    ],
    buyNum: [
        {
            rule: /^[1-9]\d*$/,
            message: "請輸入正確的購買張數",
        },
    ],
});
const rules1 = reactive({ // 市价
    buyNum: [
        {
            rule: /^[1-9]\d*$/,
            message: "請輸入正確的購買張數",
        },
    ],
});
function validate0(key) {
    let flag = true;
    rules0[key].forEach((v) => {
        if (!v.rule.test(form1[key])) {
            // toast(v.message)
            flag = false;
            return false;
        }
    });
    return flag;
}
function validate1(key) {
    let flag = true;
    rules1[key].forEach((v) => {
        if (!v.rule.test(form2[key])) {
            // toast(v.message)
            flag = false;
            return false;
        }
    });
    return flag;
}
const show = ref(false)
watch(show, async (n, o) => {
    getUserMoney()
})

// 提交申请
async function submit(bool = false) {
    if (!bool) {
        if (currentType.value == 0) {
            if (!validate0("checkPrice")) return; //validate('username')为false才执行
            if (!validate0("buyNum")) return; //validate('password')为false才执行
            // 限价提交
            let buyNum = Number(form1.buyNum) * 1000
            const { status, msg } = await requestApi.buyCheckPrice({ checkPrice: form1.checkPrice, buyNum, ...param })
            if (status == 0) {
                toast(msg)
            } else {
                toast(msg)
            }
        } else {
            if (!validate1("buyNum")) return; //validate('password')为false才执行
            let buyNum = Number(form2.buyNum) * 1000
            const { status, msg } = await requestApi.buy({ buyNum, ...param2 })
            // 市价提交
            if (status == 0) {
                toast(msg)
            } else {
                toast(msg)
            }
        }
    } else {
        // 红利股票
        const { status, msg } = await requestApi.buyRedStock(param3)
        if (status == 0) {
            toast(msg)
        } else {
            toast(msg)
        }
    }
    show.value = false
}


const header = ref()
const isBuy = ref(true)
async function getHistory() {
    const res = await getSingleStock() // 获取股票信息
    initeKline(res) // 初始化股票 K 线图
}
let timer = null
onLoad(e => {
    uni.showLoading({
        title: '加载中'
    });
    stockCode.value = JSON.parse(e.code) // 获取股票代码
    option.stockCode = JSON.parse(e.code) // 设置股票代码
    param.stockCode = JSON.parse(e.code) // 设置股票代码
    param2.stockCode = JSON.parse(e.code) // 设置股票代码
    if (e.nobuy) {
        isBuy.value = JSON.parse(e.nobuy) // 判断是否是红利股票
        param3.id = JSON.parse(e.id) // 设置红利股票的 id
    }
    getHistory()
    timer = setInterval(() => {
        getHistory()
    }, 6000)
    header.value = getToken() // 获取 token
})
onUnload(() => {
    clearInterval(timer)
    console.log(1);
})
onPullDownRefresh(async () => {
    const res = await getSingleStock()
    setTimeout(() => {
        initeKline(res)
        uni.stopPullDownRefresh();
    }, 1000);
})

</script>
<script>
var wv; //计划创建的webview
export default {
    onReady() {
        // #ifdef APP-PLUS
        var currentWebview = this.$scope
            .$getAppWebview() //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效
        setTimeout(function () {
            wv = currentWebview.children()[0]
            wv.setStyle({
                top: 350,
                left: 35,
                height: 240,
                width: 350
            })
        }, 1000); //如果是页面初始化调用时，需要延时一下
        // #endif
    }
};
</script>

<style lang="scss">
page {
    background-color: #171921;
}

.header {
    width: 100%;
    height: 88rpx;
    padding-top: 20rpx;
    //  #ifndef H5
    padding-top: 80rpx;
    //  #endif
    padding-bottom: 15rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    background-color: #202129;

    .title {
        text-align: center;
        color: #fff;
        margin: 0 auto;
        padding-right: 104rpx;
        font-size: 32rpx;
    }

    .img-title {
        width: 58rpx;
        height: 58rpx;
        margin-left: 46rpx;
    }
}

.main {
    padding-top: 108rpx;
    //  #ifndef H5
    padding-top: 196rpx;
    //  #endif
    width: 100%;
    padding-left: 40rpx;
    padding-right: 40rpx;

    .section1 {
        display: flex;
        justify-content: space-between;

        .left {
            display: flex;
            align-items: center;

            .price-rate {
                display: flex;
                flex-direction: column;
                align-items: center;
                margin-right: 11rpx;

                .price {
                    font-size: 40rpx
                }

                .rate {
                    display: flex;
                    align-items: center;

                    .chajia {
                        margin-right: 20rpx;
                    }
                }
            }

            .red {
                color: #F04848;
            }

            .green {
                color: #22A875;
            }

            .red-green {
                width: 66rpx;
                height: 76rpx;
            }
        }

        .right {
            display: flex;
            align-items: center;

            image {
                width: 52rpx;
                height: 52rpx;
                margin-left: 52rpx;
            }
        }
    }

    .section2 {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-template-rows: repeat(2, minmax(0, 1fr));
        column-gap: 43rpx;
        row-gap: 27rpx;
        margin-top: 43rpx;

        .item {
            padding: 11.5rpx 42.5rpx 19.5rpx;
            background-color: #20212A;
            border-radius: 20rpx;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;

            .key {
                color: #878B98;
                font-size: 22rpx;
            }

            .value {
                color: #fff;
                font-size: 26rpx;
            }
        }
    }

    .section3 {
        margin-top: 33rpx;

        .time-type {
            display: flex;
            align-items: center;
            margin-bottom: 2rpx;
            border-bottom: solid #0C0E12 2rpx;

            .time-item {
                // width: 88rpx;
                margin-right: 47rpx;
                white-space: nowrap;
                color: #878B98;
                text-align: center;
                transition: all .25s;
                position: relative;

                .slider {
                    position: absolute;
                    left: 50%;
                    bottom: -5rpx;
                    transform: translateX(-50%);
                    transition: all .25s;
                    background-color: #176CED;
                    height: 4rpx;
                    width: 88rpx;
                    border-radius: 2rpx;
                }
            }

            .active {
                color: #176CED;
            }

        }

        .chartBox {
            position: relative;
            border: 1rpx solid #878B98;
            margin-bottom: 40rpx;

            // #ifdef H5
            .chart {
                margin-top: 9rpx;
                width: 100%;
                height: 600rpx;
                background-color: #171921;
            }

            .chart2 {
                margin-top: 9rpx;
                width: 100%;
                height: 500rpx;
                background-color: #171921;
            }

            .panel-box .panel-title {
                padding: 3px 10px
            }

            .panel-box .panel-body {
                position: relative
            }

            .panel-box .panel-body .chart-box {
                height: 480px
            }



            // #endif
            // #ifndef H5
            .chart {
                // margin-top: 9rpx;
                width: 100%;
                height: 470rpx;
                background-color: #171921;
            }

            // #endif
        }

    }

    // #ifdef H5
    .section4 {
        background-color: #20212A;
        border-radius: 40rpx;
        transition: all .25s;

        .buy-type {
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all .25s;

            .buy-item {
                color: #878B98;
                margin-top: 20rpx;
                font-size: 32rpx;
                width: 50%;
                height: 55rpx;
                text-align: center;
                position: relative;
                transition: all .25s;

                .slider {
                    position: absolute;
                    left: 50%;
                    bottom: 0rpx;
                    transform: translateX(-50%);
                    border-radius: 6rpx;
                    background-color: #fff;
                    width: 32rpx;
                    height: 6rpx;
                    transition: all .25s;
                }
            }

            .active {
                color: #fff;
            }

        }

        .swiperBox {

            display: flex;
            flex-direction: column;
            padding-top: 53rpx;

            .form {
                display: flex;
                justify-content: space-between;
                align-items: center;
                margin-bottom: 38rpx;

                .key {
                    color: #878B98;
                    margin-left: 88rpx;
                }

                .value {
                    width: 202rpx;
                    height: 82rpx;
                    margin-right: 88rpx;
                    background-color: #171921;
                    border-radius: 28rpx;
                    color: #878B98;
                    padding-left: 20rpx;
                    line-height: 82rpx;
                }
            }

            .switch {
                width: 100%;
                margin-top: 50rpx;
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding: 0 88rpx;
                transition: all .25s;

                view {
                    width: 175rpx;
                    height: 63rpx;
                    text-align: center;
                    border: 1rpx solid transparent;
                    border-radius: 63rpx;
                    line-height: 63rpx;
                }

                .active {
                    color: #fff;
                    background-color: #176CED;
                }

                .unactive {
                    color: #878B98;
                    background-color: transparent;
                    border: solid 1rpx #878B98;
                }
            }

            .submit-btn {
                margin: 50rpx auto;
                width: 496rpx;
                height: 96rpx;
                background-color: #176CED;
                text-align: center;
                line-height: 96rpx;
                font-size: 36rpx;
                border-radius: 204rpx;
                color: #fff;
            }
        }
    }

    // #endif

    // #ifndef H5
    .section4 {
        background-color: #20212A;
        border-radius: 40rpx;
        transition: all .25s;
        margin-top: 470rpx;

        .buy-type {
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all .25s;

            .buy-item {
                color: #878B98;
                margin-top: 20rpx;
                font-size: 32rpx;
                width: 50%;
                height: 55rpx;
                text-align: center;
                position: relative;
                transition: all .25s;

                .slider {
                    position: absolute;
                    left: 50%;
                    bottom: 0rpx;
                    transform: translateX(-50%);
                    border-radius: 6rpx;
                    background-color: #fff;
                    width: 32rpx;
                    height: 6rpx;
                    transition: all .25s;
                }
            }

            .active {
                color: #fff;
            }

        }

        .swiperBox {

            display: flex;
            flex-direction: column;
            padding-top: 53rpx;

            .form {
                display: flex;
                justify-content: space-between;
                align-items: center;
                margin-bottom: 38rpx;

                .key {
                    color: #878B98;
                    margin-left: 88rpx;
                }

                .value {
                    width: 202rpx;
                    height: 82rpx;
                    margin-right: 88rpx;
                    background-color: #171921;
                    border-radius: 28rpx;
                }
            }

        }
    }

    // #endif
}

.submit-btn {
    margin: 0 auto;
    width: 496rpx;
    height: 96rpx;
    background-color: #176CED;
    text-align: center;
    line-height: 96rpx;
    font-size: 36rpx;
    border-radius: 204rpx;
    color: #fff;
}

.popup {
    background-color: #292A36;


    .title {
        text-align: center;
        color: #fff;
        margin: 0 auto;
        font-size: 32rpx;
        padding-top: 21rpx;
    }


    .box {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        margin: 33rpx 53rpx 66rpx;
        grid-column-gap: 53rpx;
        column-gap: 53rpx;
        grid-row-gap: 25rpx;
        row-gap: 25rpx;

        .boxItem {
            width: 180rpx;
            height: 180rpx;
            background-color: #20212A;
            border-radius: 40rpx;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            align-items: center;

            .key {
                display: flex;
                justify-content: center;
                align-items: center;
                flex: 3;
                font-size: 22rpx;
                color: #878B98;
            }

            .value {
                flex: 2;
                font-size: 26rpx;
                color: #fff;
            }
        }

        .submit-btn {
            margin-bottom: 33rpx;
        }
    }
}

.heightZero {
    height: 0rpx !important;
    overflow: hidden;
}
</style>
